import Head from 'next/head'
import {GetServerSideProps} from 'next'
import nookies from 'nookies'
import type {NextApiRequest, NextApiResponse} from 'next'
import React, {useEffect} from 'react'
import {Button, Result} from 'antd'
import Layout from '../../components/layout'
import {signOut} from "../../services/api/uaa"

export const getServerSideProps: GetServerSideProps = async (context) => {
    nookies.destroy(context, 'accessToken')
    return {
        props: {},
    }
}

const SignOutPage = (req: NextApiRequest, res: NextApiResponse, props: any) => {

    useEffect(() => {
        signOut().then(res => {
        })
    })

    return (
        <>
            <div>
                <Head>
                    <title>登出</title>
                    <meta name="description" content="Generated by create next app"/>
                </Head>

                <main style={{backgroundColor: '#ffffff', padding: '60px 0'}}>
                    <section className={"renfeid-content"}>
                        <Result
                            status="success"
                            title="您已成功登出！"
                            subTitle="您的身份凭据已经成功注销，随时欢迎您再次回来。"
                            extra={[
                                <Button type="primary" key="console" href="/">
                                    回到首页
                                </Button>,
                            ]}
                        />
                    </section>
                </main>
            </div>
        </>
    )
}

SignOutPage.getLayout = (page: any) => {
    return (
        <Layout>
            {page}
        </Layout>
    )
}

export default SignOutPage